/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.ruby_string.delayed;

import moved.org.objectweb.asm.Label;
import moved.org.objectweb.asm.MethodVisitor;

public class LdcInstruction extends AbstractMethodInstruction {
	private final Object constant;

	public LdcInstruction(Object constant) {
		this.constant = constant;
	}
	
	public void update(String name, String desc, String signature, Label start, Label end,
		int index) {
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// MethodInstruction Methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public void accept(MethodVisitor methodVisitor) {
		methodVisitor.visitLdcInsn(constant);
	}

	@Override
	public void inform(MethodInstruction methodInstruction) {
		if (methodInstruction instanceof LocalVariableInstruction) {
			LocalVariableInstruction localVariableInstruction =
				(LocalVariableInstruction) methodInstruction;

			localVariableInstruction.update(this);
		}

		super.inform(methodInstruction);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object Methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		if (object == null || !(object.getClass().equals(getClass()))) {
			return false;
		}
		
		LdcInstruction other = (LdcInstruction) object;
		
		return constant.equals(other.constant);
	}
}
